<?php

namespace mz\controllers;

use mz\models\AdminModel;
use Yii;
use yii\helpers\Url;


class AdminController extends DashController
{
    public $layout = '@application/admin/views/layouts/main.php';
    public function beforeAction($action)
    {
        parent::beforeAction($action);
        if(Yii::$app->admin->isGuest){
            return $this->redirect(Url::to(['/admin/login']));
        }

        Yii::$app->view->params['username'] = self::username();
        Yii::$app->view->params['avatar'] = self::avatar();

        return true;
    }

    # 获取当前登录的用户名
    protected static function username()
    {
        return AdminModel::getUsername();
    }

    # 获取当前登录的用户的头像
    protected static function avatar()
    {
        return AdminModel::getAvatar();
    }
}